package userInterface.Panels;

import java.awt.*;
import java.awt.event.*;
import java.net.URI;
import javax.swing.*;

import logging.Logger;

/**
 * {@link userInterface.panels.PanelBase PanelBase} for viewing general application information.
 * @author BDS
 */
public class PanelAbout extends PanelBase
{
	private static final long serialVersionUID = 1L;
	
	private MouseAdapter aboutMouseAdapter;
	
	private GridBagLayout gblAboutLayout;
	
	private JLabel lblTitle;
	private JLabel lblLogo;
	private JLabel lblVersion;
	private JLabel lblWebsite;

	/**
	 * Class constructor.
	 */
	public PanelAbout()
	{
		aboutMouseAdapter = new AboutMouseAdapter();
		
		gblAboutLayout = new GridBagLayout();
        gblAboutLayout.columnWeights = new double[] { 1.0 };
		gblAboutLayout.rowWeights = new double[] { 0.0, 1.0, 0.0, 0.0 };
		setLayout(gblAboutLayout);
		
		lblTitle = new JLabel("Insim");
		lblTitle.setHorizontalAlignment(SwingConstants.CENTER);
        lblTitle.setFont(new Font(lblTitle.getFont().getName(), Font.BOLD, 12));
        GridBagConstraints gbc_lblTitle = new GridBagConstraints();
        gbc_lblTitle.fill = GridBagConstraints.BOTH;
        gbc_lblTitle.insets = new Insets(10, 10, 10, 10);
        gbc_lblTitle.gridx = 0;
        gbc_lblTitle.gridy = 0;
        add(lblTitle, gbc_lblTitle);

		lblLogo = new JLabel();
		lblLogo.setHorizontalAlignment(SwingConstants.CENTER);
		lblLogo.setIcon(new ImageIcon(getClass().getResource("/images/insim.png")));
		GridBagConstraints gbc_lblLogo = new GridBagConstraints();
		gbc_lblLogo.fill = GridBagConstraints.BOTH;
		gbc_lblLogo.insets = new Insets(0, 10, 5, 10);
		gbc_lblLogo.gridx = 0;
		gbc_lblLogo.gridy = 1;
        add(lblLogo, gbc_lblLogo);
		
		lblVersion = new JLabel("Version: 0.8.7b");
		GridBagConstraints gbc_lblVersion = new GridBagConstraints();
		gbc_lblVersion.anchor = GridBagConstraints.WEST;
		gbc_lblVersion.insets = new Insets(0, 10, 5, 10);
		gbc_lblVersion.gridx = 0;
		gbc_lblVersion.gridy = 2;
        add(lblVersion, gbc_lblVersion);

		lblWebsite = new JLabel();
		lblWebsite.setIcon(new ImageIcon(this.getClass().getResource("/images/null_d3v.png")));
		lblWebsite.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		lblWebsite.addMouseListener(aboutMouseAdapter);
        GridBagConstraints gbc_lblWebsite = new GridBagConstraints();
        gbc_lblWebsite.anchor = GridBagConstraints.SOUTHEAST;
        gbc_lblWebsite.insets = new Insets(0, 0, 10, 10);
        gbc_lblWebsite.gridx = 0;
        gbc_lblWebsite.gridy = 3;
        add(lblWebsite, gbc_lblWebsite);
	}

	/**
	 * {@link java.awt.event.MouseAdapter MouseAdapter} for {@link userInterface.panels.PanelAbout PanelAbout}
	 * {@link javax.swing.JLabel JLabels}.
	 * @author BDS
	 */
	private class AboutMouseAdapter extends MouseAdapter 
	{
		/**
		 * Opens www.null-d3v.com.
		 * @param mouseEvent The triggering {@link java.awt.event.MouseEvent MouseEvent}.
		 */
		@Override
		public void mouseClicked(MouseEvent mouseEvent)
		{
			try
			{
				Desktop.getDesktop().browse(new URI("http://www.null-d3v.com"));
			}
			catch (Exception exception) 
			{ 
				Logger.logException(exception);
			}
		}
	}
}
